@extends('layout.admin')

@section('title','订单管理')

@section('content')
<style>
	.pagelist{
		margin-left:200px;
	}
	.pagelist li a,span{
		width:40px;
		height:40px;
	}
</style>
	<div class="col-md-12" >
		<div class="panel-head"><strong class="icon-reorder"> 订单列表</strong></div>
		<form action="/admin/order/index" method='get' enctype='multipart/form-data'>
			<div id="DataTables_Table_0_length" class="dataTables_length">
				<label>显示 
				<select type='text' name="num" aria-controls="DataTables_Table_0" style='width:50px;height:30px'>
					<option value="5" @if($request->input('num') == 5) selected @endif>5</option>
					<option value="10" @if($request->input('num') == 10) selected @endif>10</option>
					<option value="15" @if($request->input('num') == 15) selected @endif>15</option>
					<option value="20" @if($request->input('num') == 20) selected @endif>20</option>
					</select> 页
				</label>
				<label style='margin-left:700px'>搜索: 
					<input aria-controls="DataTables_Table_0" type="text" name='keyword' value='{{$request->input("keyword")}}'>
					
					<button class="btn btn-small"><i class="icon-search"></i></button>
				</label>	
			
			</div>
		</form>	
			<table class="table table-hover text-center">
			    <tbody>
				    <tr>
					    <th width="8%">订单号</th>
					    <th width="8%">下单时间</th>
					    <th width="8%">用户名</th>
					    <th width="15%">收货人</th>
					    <th width="8%">订单金额</th>
					    <th width="8%">实付金额</th>
					    <th width="8%">订单状态</th>
					    <th width="15%">操作</th>
				    </tr>
				    @foreach($orders as $k=>$v)
				    <tr class="@if($k % 2 == 0) even success @else odd active @endif">
				    	
				    	<td class="order_info" id="{{$v->ord_id}}">{{$v->order_num}}</td>
				    	<td>{{date('Y-m-d h:m:s',$v->time)}}</td>
				    	<td>{{$v->username}}</td>
				    	<td>
				    		<ul class="ul text-left">
				    			<li>姓名:{{$v->consignee}}</li>
				    			<li>电话:{{$v->phone}}</li>
				    			<li>地址:{{$v->prov.$v->city.$v->county.$v->detail}}</li>
				    		</ul>
				    	</td>
				    	<td>{{$v->tp}}</td>
				    	<td></td>
				    	<td class="status">{{$status[$v->ord_sta]}}</td>
				    	<td>
				    		<button class='btn btn-info' data-toggle="modal" data-target="#myModal">发货</button><!-- </a> -->
			   				<a href="/admin/order/detail?id={{$v->ord_id}}"><button class='btn btn-success'>详情</button></a>
				    	</td>
				    </tr>
					@endforeach
			
			  	</tbody>
			</table>
		<div class='pagelist'> 
		</div>
	</div>
@endsection

@section('sendHuo')
	<!-- 发货模态框 start -->
    <!-- Button trigger modal -->
    <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
        发货
    </button>
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
    aria-hidden="false">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="false"></button>
                    <h4 class="modal-title" id="myModalLabel">
                        发货
                    </h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" action="/admin/order" method="post" role="form">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">
                                快递
                            </label>
                            <div class="col-sm-10">
                                <select name="express_name" class="form-control">
									@foreach($wlName as $k=>$v)
                                    <option value="{{$k}}">{{$v}}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label">
                                单号
                            </label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="express_code"placeholder="单号">
                            </div>
                        </div>
                        {{csrf_field()}}
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                    <button type="button" class="btn btn-primary fahuo">
                        确定
                    </button>
                </div>
                
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
    <!-- 发货模态框 end -->
    <script type="text/javascript">
    	//检测快递名和单号是否匹配

    	//发送ajax
	    $(function(){
	    	$('.fahuo').click(function(){
	    		var ord_id = $('.order_info').attr('id');
	    		var express = [];
	    		express_name = $('select[name=express_name]').val();
	    		express_code = $('input[name=express_code]').val();
	    		_token = $('input[name=_token]').val(); //必须要加,否则报 500
	    		
	    		// console.log(express);
	    		$.post('/admin/order/send',{'ord_id':ord_id,'_token':_token,'express_name':express_name,'express_code':express_code},function(data){
	    			if(data == 1){
	    				$('.status').html('已付款<br>已发货');
	    				alert('发货成功');
	    			}else{
	    				alert('发货失败');
	    			}
	    		});
	    	});
	    });
    </script>
@endsection